package com.example.receiver;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;

public class HttpPostUpdate extends Activity  {
	
	String startlat;
	String startlng;
	HTTPPOSTSENSOR posts = new HTTPPOSTSENSOR();
	
	public void curpoint(double startlat,double startlng){
	
		this.startlat = String.valueOf(startlat);
		this.startlng = String.valueOf(startlng);	
		
	}
 
	
	public class HTTPPOSTSENSOR extends AsyncTask<String,String,String> {
		  

	       
		@Override
		public String  doInBackground(String... urls) {
			// TODO Auto-generated method stub
			
			String result = "";

		
			ArrayList<NameValuePair> data = new ArrayList<NameValuePair>();
			data.add(new BasicNameValuePair("deslat", ""+startlat));
			Log.d("lat lat",""+startlat);
			data.add(new BasicNameValuePair("deslng", ""+startlng));
			HttpClient client = new DefaultHttpClient();
			HttpPost post = new  HttpPost(urls[0]);
			Log.d("doin2","doin2");
			
			
				try {
					
					post.setEntity(new UrlEncodedFormEntity(data,HTTP.UTF_8));
					HttpResponse response = client.execute(post);
					HttpEntity entity = response.getEntity();
				
					if(entity != null){
						InputStream inputStream = entity.getContent();
						BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
						StringBuilder sb = new StringBuilder();
						String line = null;
						
						while((line = reader.readLine()) != null){
							sb.append(line + "\n");
						}
						
						
						inputStream.close();
						result = sb.toString();
						Log.d("resultt",""+result);
					}				
				} catch (Exception e) {
					e.printStackTrace();
			}
				return null;		
			
		}


	 }

}
